 <?php
session_start();
if (isset($_SESSION["account"])) {
?>
<?php require_once('common/header.php'); ?>
<?php require_once('common/sidebar.php'); ?> 
    <div class="main-content app-content mt-0">
        <div class="side-app">
            <!--占位-->
<div class="card"> </div>
<!--占位-->
            <!-- CONTAINER -->
            <div class="main-container container-fluid">
                <!-- PAGE-HEADER -->
                <div class="row row-sm">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <h3 class="card-title">余额变动记录</h3>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                     <table class="table table-bordered text-nowrap border-bottom" id="responsive-datatable">
                                        <thead>
                                            <tr>
                                                <th class="wd-10p border-bottom-0">账号</th>
                                                <th class="wd-10p border-bottom-0">订单号</th>
                                                <th class="wd-10p border-bottom-0">收件人</th>
                                                <th class="wd-10p border-bottom-0">订单状态</th>
                                                <th class="wd-10p border-bottom-0">类型</th>
                                                <th class="wd-10p border-bottom-0">金额</th>
                                                <th class="wd-10p border-bottom-0">状态</th>
                                                <th class="wd-10p border-bottom-0">备注</th>
                                                <th class="wd-10p border-bottom-0">创建时间</th>
                                                <th class="wd-10p border-bottom-0">到账时间</th>
                                            </tr>
                                        </thead>
                                        <tbody id="revenue-table">
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- CONTAINER CLOSED -->
        </div>
    </div>
      <?php
        session_start();
        include_once("../untils/conn.php");
        mysqli_query($con, "set names utf8");
        
        // 获取当前正在登录的账号信息的代理
        $proxy_acc = $_SESSION["account"];
        
        // 查询proxy表中的数据
        $query = "SELECT proxy_rename_sta FROM proxy WHERE proxy_acc = '$proxy_acc'";
        $result = mysqli_query($con, $query);
        $row = mysqli_fetch_assoc($result);
        
        if ($row) {
            $proxy_rename_sta = $row['proxy_rename_sta'];
        ?>
        
        <div class="modal fade" id="modaldemo5" data-bs-backdrop="static" data-bs-keyboard="false">
            <div class="modal-dialog modal-dialog-centered text-center" role="document">
                <div class="modal-content tx-size-sm">
                    <div class="modal-body text-center p-4 pb-5">
                        <i class="icon icon-close fs-70 text-danger lh-1 my-5 d-inline-block"></i>
                        <h4 class="text-danger">警告: 您的账号未实名！</h4>
                        <p class="mg-b-20 mg-x-20">平台要求所有代理商必须实名！否则无法使用平台功能！</p>
                        <a href="profile.php" class="btn btn-primary pd-x-25">去实名</a>
                    </div>
                </div>
            </div>
        </div>
        
        
            <!--/div-->
    <script src="assets/js/jquery.min.js"></script>
    
       <script>
        $(document).ready(function() {
           $.ajax({
                url: "controller/GetRevenue.php",
                type: "GET",
                dataType: "json",
                success: function(data) {
                    var html = "";
                    for (var i = 0; i < data.length; i++) {
                        var row = data[i];
                        var oderstaText = (row.odersta == 0 ? "未处理" : (row.odersta == 1 ? "已下单" : (row.odersta == 2 ? "已发货" : (row.odersta == 3 ? "已完成" : "开卡失败"))));
                        var typeText = (row.type == 0 ? "返佣" : "扣费");
                        var statusText = (row.status == 0 ? "待结算" : (row.status == 1 ? "结算中" : (row.status == 2 ? "已结算" : (row.status == 3 ? "已扣费" : "未知状态"))));
                        
                        html += `<tr>
                                    <td>${row.account}</td>
                                    <td>${row.oderid}</td>
                                    <td>${row.name}</td>
                                    <td>${oderstaText}</td>
                                    <td>${typeText}</td>
                                    <td>￥${row.price}</td>
                                    <td>${statusText}</td>
                                    <td>${row.notes}</td>
                                    <td>${row.crtime}</td>
                                    <td>${row.dztime}</td>
                                </tr>`;
                    }
                    $("#revenue-table").html(html);
                },
                error: function(error) {
                    console.log(error);
                }
            });
        });
        
    $(document).ready(function() {
        <?php
        if ($proxy_rename_sta == 0) {
            // 未实名认证
            echo '$("#modaldemo5").modal("show");';
            echo '$("#modaldemo5").modal({backdrop: "static", keyboard: false});';
        } elseif ($proxy_rename_sta == 1) {
            // 已实名认证
            echo '$("#modaldemo5").modal("hide");';
        }
        ?>
    });
</script>

<?php
} else {
    // 未找到相关数据
    // echo '数据不存在';
}
?>

<?php require_once('common/footer.php'); ?>
 <?php
} else {
  echo "<script>alert('登录过过期，没有权限访问该页面');location.href='login.html';</script>";
}